<?php
/**
 * 还桶管理
 * * edition ：v1
 * create time：2021-06-08
 * author: acker
 */
namespace App\Admin\Controllers\Order;

use App\Admin\Actions\Order\ReturnBucketAudio;
use App\Admin\Exporter\Order\OrderExpoter;
use App\Http\Controllers\Controller;
use App\Models\yb\NetworkReturnBucketModel;
use Encore\Admin\Form;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ReturnBucketController extends Controller
{
    use ModelForm;

    protected $header = '还桶管理';

    /**
     * 工作状态列表
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header($this->header);
            $content->description('列表');
            $content->body($this->grid());

        });
    }

    public function grid(){

        $grid = new Grid(new NetworkReturnBucketModel());

        $grid->model()->orderBy('created_at', 'DESC');

        $grid->column('order_sn','订单编号')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });

        $grid->column('Network.name','网点名称')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });

        $grid->column('Network.mobile','网点电话')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        });

        $grid->column('Goods.goods_title','商品名称')->display(function($filed){
            return empty($filed) ?  config('view.EmptyData') : $filed;
        });

        $grid->column('bucket_number','还桶数量')->display(function($filed){
            return empty($filed) ?  config('view.EmptyData') : $filed;
        });

        $grid->column('barrel_deposit','桶押金')->display(function($filed){
            return empty($filed) ?  config('view.EmptyData') : "¥".$filed;
        });

        $grid->column('total_barrel_deposit','总金额')->display(function($filed){
            return empty($filed) ?  config('view.EmptyData') : "¥".$filed;
        });

        $grid->column('remark','备注')->display(function($filed){
            return empty($filed) ?  config('view.EmptyData') : $filed;
        });

        $grid->column('status','状态')->using([
            '0'=>'待审核',
            '1'=>'审核通过',
            '2'=>'审核不通过',
        ], '未知')->dot([
            0 => 'danger',
            1 => 'info',
            2 => 'warning',
        ], 'success');

        $grid->column('created_at','创建时间')->display(function($filed){
            return empty($filed) ? config('view.EmptyData') : $filed;
        })->sortable();

        $grid->column('id','审核')->display(function ($id, $column) use ($grid) {

            if($this->status == 0){
                $action = new ReturnBucketAudio();
                return $action
                    ->asColumn()
                    ->setGrid($grid)
                    ->setColumn($column)
                    ->setRow($this);
            }

        });
        //搜索
        $grid->filter(function($filter){
            $filter->column(1/2, function ($filter) {
                $filter->like('order_sn','订单编号');
                $filter->like('Goods.goods_title','商品名称');
                $filter->between('created_at', '还桶时间')->datetime();
            });
            $filter->column(1/2, function ($filter) {
                $filter->like('Network.name','网点名称');
                $filter->equal('status', '状态')->select([
                    '0'=>'待审核',
                    '1'=>'审核通过',
                    '2'=>'审核不通过',
                ]);
            });
            $filter->disableIdFilter();
        });

        $grid->fixColumns(1, -1);

        $grid->exporter(new OrderExpoter());

        $grid->actions(function($actions){
            $actions->disableDelete();
            $actions->disableEdit();
        });

        $grid->disableExport();

        $grid->disableCreateButton();

        $grid->tools(function ($tools) {
            $tools->batch(function ($batch) {
                $batch->disableDelete();
            });
        });

        $grid->paginate(10);

        return $grid;
    }





}